66

Beginner’s Guide to Code Algorithms

66

STEP 22 Continued (fill emptycells)

        If sbox(n, p) <> ““ Then notahome =​ 1

        For kk =​ 1 To 9

          If cantbelist(n, p, kk) =​ putnumber Then notahome =​ 1

        Next kk

        If notahome =​ 1 Then

          notahomecount =​ notahomecount +​ 1

        Else

          homerow =​ n

          homecol =​ p

        End If

      Next l

    Next k

    If notahomecount =​ 8 Then

        sbox(homerow, homecol) =​ putnumber

        Call updatecantbelist(putnumber, homerow, homecol)

        Cells(homerow, homecol) =​ sbox(homerow, homecol)

      End If

    End If

Next j

Next i

:

Next putnumber

End Sub

STEP 22 Continued (Refreshcantbelist)

Sub RefreshCantbelist()

    For i =​ 1 To 9

      For j =​ 1 To 9

        For k =​ 1 To 9

    ‘*      check all columns in this row

          If j <> k Then

            ‘ For m =​ 1 To 9

            If sbox(i, k) > 0 Then

              foundincantbelist =​ 0

              For kk =​ 1 To 9

              If sbox(i, k) =​ cantbelist(i, j, kk) Then foundincantbelist =​ 1

              Next kk

              If foundincantbelist =​ 0 Then

              cantbelist(i, j, NextEmptyLocation(i, j)) =​ sbox(i, k)

              End If

            End If

            ‘Next m

          End If

        Next k

‘*        check all rows in this column

        For k =​ 1 To 9

          If i <> k Then

‘ For m =​ 1 To 9

            If sbox(k, j) > 0 Then

        foundincantbelist =​ 0

        For kk =​ 1 To 9